package co.edu.unal.view;

import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;

import co.edu.unal.controller.App;
import co.edu.unal.controller.tool.LineCreationTool;
import co.edu.unal.controller.tool.SelectionTool;
import co.edu.unal.controller.tool.Tool;

public class Canvas extends JPanel {

	private static final long serialVersionUID = 1L;

	public Canvas() {
		tool = new Tool[NUM_TOOLS];

		tool[SELECTION] = new SelectionTool();
	    tool[LINE_CT] = new LineCreationTool(this);
		// tool[RECT_CT] = new RectCreationTool(this);
		// tool[ELIPSE_CT] = new ElipseCreationTool(this);
		// tool[TEXT_CT] = new TextCreationTool(this);

		 activeTool = tool[LINE_CT];
		//activeTool = tool[SELECTION];// temporal

		// State design pattern
		addMouseListener(new MouseAdapter() {
			/** clase interna y anonima(Mouse Adapter) */
			@Override
			public void mousePressed(MouseEvent e) {
				activeTool.mousePressed(e);

			}

			@Override
			public void mouseReleased(MouseEvent e) {
				activeTool.mouseReleased(e);
			}
		});
		addMouseMotionListener(new MouseAdapter() {
			@Override
			public void mouseMoved(MouseEvent e) {
			}

			@Override
			public void mouseDragged(MouseEvent e) {
			}
		});
	}

	public void paint(Graphics g) {
		super.paint(g);
		App.getInstance().paint(g);
	}

	private Tool[] tool;
	private Tool activeTool;

	public static final int SELECTION = 0;
	public static final int LINE_CT = 1;
	public static final int RECT_CT = 2;
	public static final int ELIPSE_CT = 3;
	public static final int TEXT_CT = 4;
	public static final int NUM_TOOLS = 5;

}
